/**   
 * Copyright © 2019 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * @Description:TODO(功能)
 * @className LoginListener.java
 * @Package: com.erp.listener 
 * @author: yj   
 * @date: 2019年2月19日 上午11:24:19 
 */
package com.erp.listener;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * @className LoginListener.java
 * @author yj
 * @Description:TODO(功能)
 * @Date 2019年2月19日
 */
public class LoginUserListener implements HttpSessionAttributeListener {

	@Override
	public void attributeAdded(HttpSessionBindingEvent se) {
		System.out.println("---有用户登陆---");
		
		ServletContext app = se.getSession().getServletContext();
		Object count = app.getAttribute("loginUser");
		if (count == null) {
			app.setAttribute("loginUser", 1);
		} else {
			app.setAttribute("loginUser", Integer.parseInt(count.toString()) + 1);
		}
		
	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent se) {
		System.out.println("---有用户退出登陆---");

		ServletContext app = se.getSession().getServletContext();
		Object count = app.getAttribute("loginUser");
		if (count != null) {
			app.setAttribute("loginUser", Integer.parseInt(count.toString()) - 1);
		}
	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent se) {

	}

}
